package com.gm.springboot.controller;

import com.github.pagehelper.PageInfo;
import com.gm.springboot.bean.Major;
import com.gm.springboot.service.MajorService;
import org.apache.ibatis.annotations.Insert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author Administrator
 * @Date 2020/7/2 17:21
 **/
@Controller
public class MajorController {
    @Autowired
    MajorService majorService;
    @GetMapping("/majors")
    public String findStudentAll(@RequestParam(defaultValue = "1")Integer page,
                                 @RequestParam(defaultValue = "5")Integer size,
                                 Model model
    ){
        List<Major> list=this.majorService.findMajorAll(page,size);
        PageInfo<Major> pageInfo=new PageInfo<>(list);
        model.addAttribute("majors",pageInfo);
        return "major-list";

    }
    @GetMapping("/delMajor/{mid}")
    public String delMajor(@PathVariable("mid")Integer mid){
        this.majorService.delMajor(mid);
        return "redirect:/majors";
    }
    @PostMapping("/addMajor")
    public String addMajor(Major major){
        this.majorService.addMajor(major);
        return "redirect:/majors";
    }
    @GetMapping("/toMajorPage/{mid}")
    public String toMajorPage(@PathVariable("mid")Integer mid,Model model){
        Major major=this.majorService.findMajorById(mid);
        model.addAttribute("major",major);
        return "major-upd";
    }
    @PutMapping("/updMajor")
    public String updMajor(Major major){
        this.majorService.updMajor(major);
        return "redirect:majors";
    }
}
